using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
using objetos;
using dados;
using System.IO;
using System.Xml.Serialization;

namespace negocios
{
	#region TB_CONTATO
	/// <summary>
	/// This object represents the properties and methods of a TB_CONTATO.
	/// </summary>
	public class BLL_TB_CONTATO : System.Web.UI.Page
	{		
		DAL_TB_CONTATO DAL = new DAL_TB_CONTATO();
		
		#region METODOS PROCEDURES

        public DataTable Dt_contato
        {
            get
            {
                if (Session["Dt_contato"] == null)
                {
                    Dt_contato = CriarDataTable();
                }
                return (DataTable)Session["Dt_contato"];
            }
            set { Session["Dt_contato"] = value; }
        }


		/// <summary>
		/// Incluir via procedure
		/// </summary>
		public int Incluir(OBJ_TB_CONTATO obj)
		{
			return	DAL.Incluir(obj);
			
		}
					 
		
		/// <summary>
		/// Alterar via procedure
		/// </summary>
		public void Alterar(OBJ_TB_CONTATO obj)
		{
			DAL.Alterar(obj);	
		}
		
		/// <summary>
		/// Excluir via procedure
		/// </summary>
		public void Excluir(OBJ_TB_CONTATO obj)
		{
			DAL.Excluir(obj);	
		}
		
		/// <summary>
		/// Excluir Lista via procedure
		/// </summary>
		public void ExcluirLista(List<OBJ_TB_CONTATO> lista)
		{
				foreach (OBJ_TB_CONTATO obj in lista)
            	{
                this.Excluir(obj);
            	}
			
		}
						
		/// <summary>
		/// Pesquisar Parametros Where, OrderBy, PageIndex, PageSize
		/// </summary>		
		public DataSet Selecionar(string Where, string OrderBy, int PageIndex, int PageSize)
		{
			
			return DAL.Selecionar(Where,OrderBy,PageIndex,PageSize);
			
		}		
		
		
		/// <summary>
		/// Retorna Objeto por ID
		/// </summary>
		public OBJ_TB_CONTATO SelecionarObjetoPorId(int id)
		{
			return DAL.SelecionarObjetoPorId(id);
			
		}
				
			
		/// <summary>
		/// Retorna DataSet Parametros Where, OrderBy
		/// </summary>	
		public DataSet Selecionar(String Where, String OrderBy)
        {
            return DAL.Selecionar(Where, OrderBy);
        }
		
		/// <summary>
		/// Retorna DataSet
		/// </summary>	
		public DataSet Selecionar()
        {
            return DAL.Selecionar();
        }
			
		
		/// <summary>
		/// Retorna uma lista de objetos por parametro Where, OrderBy
		/// </summary>
		public List<OBJ_TB_CONTATO>SelecionarLista(String Where, String OrderBy)
		{						
			return 	DAL.SelecionarLista(Where,OrderBy);
		}
		
		
		/// <summary>
		/// Retorna uma lista de objetos por parametro 
		/// </summary>
		public List<OBJ_TB_CONTATO>SelecionarLista()
		{						
			return 	DAL.SelecionarLista();
		}
		
		public void PreencheControle(System.Web.UI.Control controle, bool selecione)
        {
            if (controle is DropDownList)
            {
                DropDownList ddl = (DropDownList)controle;
                ddl.Items.Clear();
                foreach (OBJ_TB_CONTATO obj in DAL.SelecionarLista())
                {
                    ddl.Items.Add(new ListItem(obj.id_cadastro.ToString(), obj.id.ToString()));
                }
                
                if (selecione)
                {
                    ddl.Items.Insert(0, new ListItem("Selecione", ""));
                    ddl.SelectedIndex = 0;
                }

                ddl.DataBind();
            }


            if (controle is ListBox)
            {
                ListBox lst = (ListBox)controle;
                lst.Items.Clear();
                foreach (OBJ_TB_CONTATO obj in DAL.SelecionarLista())
                {
                    lst.Items.Add(new ListItem(obj.id_cadastro.ToString(), obj.id.ToString()));
                }

                if (selecione)
                {
                    lst.Items.Insert(0, new ListItem("Selecione", ""));
                    lst.SelectedIndex = 0;
                }

                lst.DataBind();
            }

        }										
			
		
		public DataSet ListaCampos()
		{
			 return DAL.ListaCampos();
		}



        public void SerializeObjeto(OBJ_TB_CONTATO obj, String arquivo)
        {
            try
            {
                // Create file to save the data to
                FileStream fs = new FileStream(arquivo, FileMode.Create);
                // Create an XmlSerializer object to perform the serialization
                XmlSerializer xs = new XmlSerializer(typeof(OBJ_TB_CONTATO));
                // Use the XmlSerializer object to serialize the data to the file

                xs.Serialize(fs, obj); 
                // Close the file
                fs.Close();
            }
            catch (Exception)
            {

                throw;
            }

        }
        
        public void SerializeLista(List<OBJ_TB_CONTATO> obj, String arquivo)
        {
            try
            {
                // Create file to save the data to
                FileStream fs = new FileStream(arquivo, FileMode.Create);
                // Create an XmlSerializer object to perform the serialization
                XmlSerializer xs = new XmlSerializer(typeof(List<OBJ_TB_CONTATO>));
                // Use the XmlSerializer object to serialize the data to the file

                xs.Serialize(fs, obj);
                // Close the file
                fs.Close();
            }
            catch (Exception)
            {

                throw;
            }

        }

        public OBJ_TB_CONTATO DeserializeObjeto(String arquivo)
        {
            try
            {
                // C#
                // Open file to read the data from
                FileStream fs = new FileStream(arquivo, FileMode.Open);
                // Create an XmlSerializer object to perform the deserialization
                XmlSerializer xs = new XmlSerializer(typeof(OBJ_TB_CONTATO));
                // Use the XmlSerializer object to deserialize the data from the file
                OBJ_TB_CONTATO obj = (OBJ_TB_CONTATO)xs.Deserialize(fs);
                // Close the file
                fs.Close();

                return obj;
            }
            catch (Exception)
            {

                throw;
            }

        }

        public List<OBJ_TB_CONTATO> DeserializeLista(String arquivo)
        {
            try
            {
                // C#
                // Open file to read the data from
                FileStream fs = new FileStream(arquivo, FileMode.Open);
                // Create an XmlSerializer object to perform the deserialization
                XmlSerializer xs = new XmlSerializer(typeof(List<OBJ_TB_CONTATO>));
                // Use the XmlSerializer object to deserialize the data from the file
                List<OBJ_TB_CONTATO> obj = (List<OBJ_TB_CONTATO>)xs.Deserialize(fs);
                // Close the file
                fs.Close();

                return obj;
            }
            catch (Exception)
            {

                throw;
            }

        }

        /// <summary>
        /// Preenche Data Table
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        public DataTable PreencheDataTable(DataTable dt, OBJ_TB_CONTATO item)
        {

            return DAL.PreencheDataTable(dt, item);
        }


        /// <summary>
        /// Criar Data Table
        /// </summary>
        /// <returns></returns>
        public DataTable CriarDataTable()
        {
            return DAL.CriarDataTable();
        }

		#endregion
	}
	#endregion
}

